/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MeshlessShapeFunctions;

/**
 *
 * @author mark
 */
public class JStKernel implements IKernelFunction{
	private double rho;
	
	public JStKernel(double rho){
		this.rho = rho;
		
	}

	public double evaluate(double x) {
        if(Math.abs(x)<=1){
            return Math.sqrt(4.0/Math.PI)*Math.pow((1-x*x),4);
        }else{
            return 0.0;
        }
    }
	
	public static double evaluate(double x,double xi,double rho) {
		double tmp = (xi-x)/rho;
        if(Math.abs(tmp)<=1){
            return Math.sqrt(4.0/Math.PI)*Math.pow((1-tmp*tmp),4);
        }else{
            return 0.0;
        }
    }
	
    public double evaluateDerivaty(double x) {
        if(Math.abs(x)<=1){
        	return - 8*Math.sqrt(4.0/Math.PI) * Math.pow(1-x*x, 3) * x/rho;
        }else{
            return 0.0;
        }
    }
    
	@Override
	public double evaluateSecondDerivaty(double x) {
		if(Math.abs(x)<=1){
		return -Math.sqrt(4.0/Math.PI) * ( -48 * Math.pow(1-x*x, 2) * x * x + 8*Math.pow(1-x*x, 3) )/rho/rho;
      }else{
          return 0.0;
      }
	}
	
    public double evaluateNorm(double x, double y) {
        double xx = Math.abs(Math.sqrt(x*x+y*y));
        if(xx>1){ return 0.0;}
        else{
            //return Math.sqrt(4.0/Math.PI)*Math.pow((1-xx),2);
            return Math.sqrt(4.0/Math.PI)*Math.pow((1-xx*xx),4);
            //return Math.sqrt(4.0/Math.PI) * Math.pow(     Math.pow(   1-Math.pow(x,2)-Math.pow(y,2), 2 ),2              );
        }
    }

    public double evaluateSque(double x, double y) {
        return evaluateNorm(x, 0)*evaluateNorm(0, y);
    }

    public double evaluatePrimeNormX(double x, double y) {
        //return Math.sqrt(4.0/Math.PI)*4*(Math.pow(1-sqr(abs(y1-x1),2)/sqr(rox)-sqr(abs(y2-x2))/sqr(roy)))*(1-sqr(abs(y1-x1))/sqr(rox)-sqr(abs(y2-x2))/sqr(roy))*(-2)*(y1-x1)/sqr(rox);
        double xx = Math.abs(Math.sqrt(x*x+y*y));
        return -Math.sqrt(4.0/Math.PI) * 2*(1-xx)* ( x/xx );
    }

    public double evaluatePrimeNormY(double x, double y) {
        double xx = Math.abs(Math.sqrt(x*x+y*y));
        return -Math.sqrt(4.0/Math.PI) * 2*(1-xx)* ( y/xx );
    }

    public double evaluatePrimeSqueX(double x, double y) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public double evaluatePrimeSqueY(double x, double y) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public static void main(String[] args){
        double a =-1.5,b=1.5,
        h=0.01;
        double x = a;

        IKernelFunction f  = new JStKernel(1);

        while(x<b+h){
            System.out.println(x+"\t"+f.evaluateDerivaty(x));
            x+=h;
        }
        
        
        
    }


}
